import React ,{ Component,PropTypes } from 'react'
import { Link, browserHistory } from 'react-router';

require('../css/ConfirmAdd.css');
class ConfirmAdd extends Component {

	constructor (props, context) {
	    super(props, context)
	    this.state = {

			}
	}

	componentWillMount() {
	  this.query = JSON.parse(sessionStorage.getItem('confirmCharge'));
      console.log(this.query)
    }


    goPay(ev) {
    	var _this=this
     	let {gbwcpr,pathSuccess} = this.query;
     	let param=encodeURIComponent(JSON.stringify(gbwcpr))
			try {
				WeixinJSBridge.invoke(
				    'getBrandWCPayRequest',
						gbwcpr,
						function(res){
								if (res.err_msg == "get_brand_wcpay_request:ok" ) {
									browserHistory.push(pathSuccess)
								} else {
									console.log("错误原因"+res)
									_this.goFailPage();
								}
								// 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg 将在用户支付成功后返回 ok，但幵丌保证它绝对可靠。
						}
					);
			} catch (ex) {
					_this.goFailPage();
			}
			ev && ev.preventDefault();
			// let l = location.href.substring(0, location.href.length-location.pathname.length);
   //      	location.href = "http://api.kakakj.com/cafunedev/pale-checkout.html?"+
   //        	"redir="+encodeURIComponent(l+'/result')+
   //        	"&gbwcpr="+param+
   //        	"&success=0&fail=%24ex";

   //     		ev && ev.preventDefault();
	}

	// goFailPage() {
	// 		browserHistory.push(`/failadd`);
	// }

    goBack() {
		  browserHistory.go(-1);
	}
	render() {
		let netPay = this.query.netPay;
		return (
			<div className="confirm-wapper">
				<div className="confirm-info">
						<div className="cinfo-icon">
								<svg  width="80" height="80">
								    <circle cx="40" cy="40" r="40" fill="#FFD11A"></circle>
										<path d="M28 32 C 28 12, 52 12, 52 32" stroke="#fff" strokeWidth="6" fill="transparent"
										strokeLinecap="round" strokeLinejoin="round"/>
										<path d="M52 32 Q 36 46, 40 50" stroke="#fff" strokeWidth="6" fill="transparent"
										strokeLinecap="round" strokeLinejoin="round"/>
										<circle cx="40" cy="60" r="4" fill="white"></circle>
								</svg>
				    	</div>
						<p className="cinfo-money">
							支付金额
							<span className="rm">￥<span className="rmsum">{netPay}</span></span>
						</p>
						
				</div>
				<div className="confirm-handle">
					<span onTouchStart={this.goPay.bind(this)} className="handle-btn orange-btn">确认支付</span>
					<span onTouchStart={this.goBack.bind(this)} className="handle-btn gray-btn">取消</span>
				</div>
			</div>

		)
	}
}

module.exports = ConfirmAdd
